﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.IBll;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class ApitokenValidHelper
    {
        /// <summary>
        /// 传递的是商家的APitoken值
        /// </summary>
        /// <param name="apiToken"></param>
        /// <returns></returns>
        public static Model.Common.JsonResult IsShangJiaValid(string apiToken)
        {
            Model.Common.JsonResult jsonResult = new Model.Common.JsonResult();
            if (string.IsNullOrEmpty(apiToken) || apiToken.Trim().Length == 0)
            {
                jsonResult.Success = false;
                jsonResult.LoginStatus = Chinaer.Core.BaseCore.LoginStatus.NonLogin;
                jsonResult.ErrorMessage = "Apitoken为null";
                return jsonResult;
            }
            //根据apiToken 获取到用户名
            IShangJia shangJia = new Bll.ShangJia();
            var shangJiaDTO=shangJia.GetByApiToken(apiToken);
            if (shangJiaDTO.CheckIsNull().Success==false|| string.IsNullOrEmpty(shangJiaDTO.LoginName) || shangJiaDTO.LoginName.Trim().Length == 0)
            {
                jsonResult.Success = false;
                jsonResult.LoginStatus = Chinaer.Core.BaseCore.LoginStatus.UserNotExists;
                jsonResult.ErrorMessage = "UserName is null";
                return jsonResult;
            }

           //下面就表示用户是存在的 也就是表示是成功登陆的
            jsonResult.Success = true;
            jsonResult.LoginStatus = Chinaer.Core.BaseCore.LoginStatus.Success;
            return jsonResult;                        
        }
    }
}
